{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(r'./data/test_2022.csv', encoding = 'utf-8')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>1990</td>\n",
       "      <td>28.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.077</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1996</td>\n",
       "      <td>51.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>93.0</td>\n",
       "      <td>8.300</td>\n",
       "      <td>8.24</td>\n",
       "      <td>14.1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "0   1   0  1996  30.1             无记录  106.0    3.818     7.89       0.0   \n",
       "1   2   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7   \n",
       "2   3   1  1988  36.5             无记录   85.0    7.131     0.00      40.1   \n",
       "3   4   1  1992  29.5             无记录   91.0    7.041     0.00       0.0   \n",
       "4   5   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0   \n",
       "5   6   1  1990  28.0             无记录    NaN    6.077     0.00       0.0   \n",
       "6   7   1  1996  51.0             无记录   93.0    8.300     8.24      14.1   \n",
       "\n",
       "   患有糖尿病标识  \n",
       "0        0  \n",
       "1        0  \n",
       "2        1  \n",
       "3        0  \n",
       "4        1  \n",
       "5        0  \n",
       "6        0  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "编号            int64\n",
       "性别            int64\n",
       "出生年份          int64\n",
       "体重指数        float64\n",
       "糖尿病家族史       object\n",
       "舒张压         float64\n",
       "口服耐糖量测试     float64\n",
       "胰岛素释放实验     float64\n",
       "肱三头肌皮褶厚度    float64\n",
       "患有糖尿病标识       int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 5070 entries, 0 to 5069\n",
      "Data columns (total 10 columns):\n",
      " #   Column    Non-Null Count  Dtype  \n",
      "---  ------    --------------  -----  \n",
      " 0   编号        5070 non-null   int64  \n",
      " 1   性别        5070 non-null   int64  \n",
      " 2   出生年份      5070 non-null   int64  \n",
      " 3   体重指数      5070 non-null   float64\n",
      " 4   糖尿病家族史    5070 non-null   object \n",
      " 5   舒张压       4823 non-null   float64\n",
      " 6   口服耐糖量测试   5070 non-null   float64\n",
      " 7   胰岛素释放实验   5070 non-null   float64\n",
      " 8   肱三头肌皮褶厚度  5070 non-null   float64\n",
      " 9   患有糖尿病标识   5070 non-null   int64  \n",
      "dtypes: float64(5), int64(4), object(1)\n",
      "memory usage: 396.2+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=5070, step=1)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['编号', '性别', '出生年份', '体重指数', '糖尿病家族史', '舒张压', '口服耐糖量测试', '胰岛素释放实验',\n",
       "       '肱三头肌皮褶厚度', '患有糖尿病标识'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>4823.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "      <td>5070.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>2535.500000</td>\n",
       "      <td>0.456805</td>\n",
       "      <td>1986.869231</td>\n",
       "      <td>37.986785</td>\n",
       "      <td>89.423595</td>\n",
       "      <td>5.612839</td>\n",
       "      <td>4.114321</td>\n",
       "      <td>6.994371</td>\n",
       "      <td>0.381854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1463.727263</td>\n",
       "      <td>0.498180</td>\n",
       "      <td>8.919737</td>\n",
       "      <td>11.447095</td>\n",
       "      <td>9.266992</td>\n",
       "      <td>2.257649</td>\n",
       "      <td>8.726001</td>\n",
       "      <td>13.651442</td>\n",
       "      <td>0.485889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1943.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1268.250000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1980.000000</td>\n",
       "      <td>28.400000</td>\n",
       "      <td>85.000000</td>\n",
       "      <td>4.314000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2535.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1987.000000</td>\n",
       "      <td>36.550000</td>\n",
       "      <td>89.000000</td>\n",
       "      <td>5.760000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>3802.750000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1995.000000</td>\n",
       "      <td>47.600000</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>7.193000</td>\n",
       "      <td>7.100000</td>\n",
       "      <td>4.120000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>5070.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2009.000000</td>\n",
       "      <td>65.900000</td>\n",
       "      <td>126.000000</td>\n",
       "      <td>10.839000</td>\n",
       "      <td>108.960000</td>\n",
       "      <td>45.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                编号           性别         出生年份         体重指数          舒张压  \\\n",
       "count  5070.000000  5070.000000  5070.000000  5070.000000  4823.000000   \n",
       "mean   2535.500000     0.456805  1986.869231    37.986785    89.423595   \n",
       "std    1463.727263     0.498180     8.919737    11.447095     9.266992   \n",
       "min       1.000000     0.000000  1943.000000     0.000000    30.000000   \n",
       "25%    1268.250000     0.000000  1980.000000    28.400000    85.000000   \n",
       "50%    2535.500000     0.000000  1987.000000    36.550000    89.000000   \n",
       "75%    3802.750000     1.000000  1995.000000    47.600000    96.000000   \n",
       "max    5070.000000     1.000000  2009.000000    65.900000   126.000000   \n",
       "\n",
       "           口服耐糖量测试      胰岛素释放实验     肱三头肌皮褶厚度      患有糖尿病标识  \n",
       "count  5070.000000  5070.000000  5070.000000  5070.000000  \n",
       "mean      5.612839     4.114321     6.994371     0.381854  \n",
       "std       2.257649     8.726001    13.651442     0.485889  \n",
       "min      -1.000000     0.000000     0.000000     0.000000  \n",
       "25%       4.314000     0.000000     0.000000     0.000000  \n",
       "50%       5.760000     0.000000     0.000000     0.000000  \n",
       "75%       7.193000     7.100000     4.120000     1.000000  \n",
       "max      10.839000   108.960000    45.000000     1.000000  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1988"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1,\"出生年份\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    1988\n",
       "2    1988\n",
       "3    1992\n",
       "Name: 出生年份, dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1:3,\"出生年份\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5065</th>\n",
       "      <td>1992</td>\n",
       "      <td>36.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5066</th>\n",
       "      <td>1991</td>\n",
       "      <td>37.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5067</th>\n",
       "      <td>1975</td>\n",
       "      <td>25.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5068</th>\n",
       "      <td>1972</td>\n",
       "      <td>28.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5069</th>\n",
       "      <td>1976</td>\n",
       "      <td>49.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5070 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      出生年份  体重指数\n",
       "0     1996  30.1\n",
       "1     1988  27.5\n",
       "2     1988  36.5\n",
       "3     1992  29.5\n",
       "4     1998  42.0\n",
       "...    ...   ...\n",
       "5065  1992  36.4\n",
       "5066  1991  37.1\n",
       "5067  1975  25.4\n",
       "5068  1972  28.5\n",
       "5069  1976  49.9\n",
       "\n",
       "[5070 rows x 2 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,[\"出生年份\",\"体重指数\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>170</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>0.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.203</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1626</th>\n",
       "      <td>1627</td>\n",
       "      <td>1</td>\n",
       "      <td>2000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.713</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2266</th>\n",
       "      <td>2267</td>\n",
       "      <td>0</td>\n",
       "      <td>2003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>父母有一方患有糖尿病</td>\n",
       "      <td>62.0</td>\n",
       "      <td>6.429</td>\n",
       "      <td>13.04</td>\n",
       "      <td>2.25</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3062</th>\n",
       "      <td>3063</td>\n",
       "      <td>0</td>\n",
       "      <td>2003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.577</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3243</th>\n",
       "      <td>3244</td>\n",
       "      <td>1</td>\n",
       "      <td>1967</td>\n",
       "      <td>0.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>100.0</td>\n",
       "      <td>6.801</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4458</th>\n",
       "      <td>4459</td>\n",
       "      <td>0</td>\n",
       "      <td>2002</td>\n",
       "      <td>0.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.351</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4488</th>\n",
       "      <td>4489</td>\n",
       "      <td>0</td>\n",
       "      <td>1951</td>\n",
       "      <td>0.0</td>\n",
       "      <td>父母有一方患有糖尿病</td>\n",
       "      <td>88.0</td>\n",
       "      <td>7.409</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4933</th>\n",
       "      <td>4934</td>\n",
       "      <td>0</td>\n",
       "      <td>2003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>父母有一方患有糖尿病</td>\n",
       "      <td>73.0</td>\n",
       "      <td>5.557</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2.25</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "169    170   1  1998   0.0             无记录    NaN    6.203     0.00      0.00   \n",
       "1626  1627   1  2000   0.0  叔叔或者姑姑有一方患有糖尿病    NaN    5.713     0.00      0.00   \n",
       "2266  2267   0  2003   0.0      父母有一方患有糖尿病   62.0    6.429    13.04      2.25   \n",
       "3062  3063   0  2003   0.0  叔叔或者姑姑有一方患有糖尿病    NaN    4.577     0.00      0.00   \n",
       "3243  3244   1  1967   0.0             无记录  100.0    6.801     0.00      0.00   \n",
       "4458  4459   0  2002   0.0             无记录    NaN    4.351     0.00      0.00   \n",
       "4488  4489   0  1951   0.0      父母有一方患有糖尿病   88.0    7.409     0.00      0.00   \n",
       "4933  4934   0  2003   0.0      父母有一方患有糖尿病   73.0    5.557     0.00      2.25   \n",
       "\n",
       "      患有糖尿病标识  \n",
       "169         0  \n",
       "1626        0  \n",
       "2266        0  \n",
       "3062        0  \n",
       "3243        1  \n",
       "4458        0  \n",
       "4488        0  \n",
       "4933        0  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"体重指数\"] < 17]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       False\n",
       "1       False\n",
       "2       False\n",
       "3       False\n",
       "4       False\n",
       "        ...  \n",
       "5065    False\n",
       "5066    False\n",
       "5067    False\n",
       "5068    False\n",
       "5069    False\n",
       "Name: 体重指数, Length: 5070, dtype: bool"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"体重指数\"] < 17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df01 = df[df[]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "18.5 <= x <=23.9  糖尿病家族史"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>1992</td>\n",
       "      <td>20.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7.053</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1999</td>\n",
       "      <td>20.2</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.953</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>22.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.121</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>88</td>\n",
       "      <td>1</td>\n",
       "      <td>1987</td>\n",
       "      <td>23.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>4.429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1976</td>\n",
       "      <td>22.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>7.024</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    编号  性别  出生年份  体重指数 糖尿病家族史   舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识\n",
       "49  50   0  1992  20.7    无记录  96.0    7.053      0.0       0.0        0\n",
       "60  61   1  1999  20.2    无记录  87.0    6.953      0.0       0.0        0\n",
       "83  84   0  1985  22.4    无记录  87.0    6.121      0.0       0.0        0\n",
       "87  88   1  1987  23.7    无记录  85.0    4.429      0.0       0.0        0\n",
       "93  94   1  1976  22.0    无记录  84.0    7.024      0.0      40.3        1"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df01 = df.loc[(df[\"体重指数\"]<=23.9) & (df[\"体重指数\"]>=18.5) & (df[\"糖尿病家族史\"]==\"无记录\"), :]\n",
    "df01.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>1992</td>\n",
       "      <td>20.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7.053</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1999</td>\n",
       "      <td>20.2</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.953</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>22.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.121</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>88</td>\n",
       "      <td>1</td>\n",
       "      <td>1987</td>\n",
       "      <td>23.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>4.429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1976</td>\n",
       "      <td>22.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>7.024</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    编号  性别  出生年份  体重指数 糖尿病家族史   舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识\n",
       "49  50   0  1992  20.7    无记录  96.0    7.053      0.0       0.0        0\n",
       "60  61   1  1999  20.2    无记录  87.0    6.953      0.0       0.0        0\n",
       "83  84   0  1985  22.4    无记录  87.0    6.121      0.0       0.0        0\n",
       "87  88   1  1987  23.7    无记录  85.0    4.429      0.0       0.0        0\n",
       "93  94   1  1976  22.0    无记录  84.0    7.024      0.0      40.3        1"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df02 = df[(df[\"体重指数\"]<=23.9) & (df[\"体重指数\"]>=18.5) & (df[\"糖尿病家族史\"]==\"无记录\")]\n",
    "df02.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>1992</td>\n",
       "      <td>20.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7.053</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1999</td>\n",
       "      <td>20.2</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.953</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>22.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.121</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>88</td>\n",
       "      <td>1</td>\n",
       "      <td>1987</td>\n",
       "      <td>23.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>4.429</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1976</td>\n",
       "      <td>22.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>7.024</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4974</th>\n",
       "      <td>4975</td>\n",
       "      <td>1</td>\n",
       "      <td>1995</td>\n",
       "      <td>21.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>5.691</td>\n",
       "      <td>0.00</td>\n",
       "      <td>19.8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4978</th>\n",
       "      <td>4979</td>\n",
       "      <td>1</td>\n",
       "      <td>1993</td>\n",
       "      <td>23.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>6.660</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4992</th>\n",
       "      <td>4993</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.891</td>\n",
       "      <td>0.00</td>\n",
       "      <td>41.4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5003</th>\n",
       "      <td>5004</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>20.9</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>7.92</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5064</th>\n",
       "      <td>5065</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.6</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.588</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>287 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        编号  性别  出生年份  体重指数 糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识\n",
       "49      50   0  1992  20.7    无记录   96.0    7.053     0.00       0.0        0\n",
       "60      61   1  1999  20.2    无记录   87.0    6.953     0.00       0.0        0\n",
       "83      84   0  1985  22.4    无记录   87.0    6.121     0.00       0.0        0\n",
       "87      88   1  1987  23.7    无记录   85.0    4.429     0.00       0.0        0\n",
       "93      94   1  1976  22.0    无记录   84.0    7.024     0.00      40.3        1\n",
       "...    ...  ..   ...   ...    ...    ...      ...      ...       ...      ...\n",
       "4974  4975   1  1995  21.3    无记录   96.0    5.691     0.00      19.8        0\n",
       "4978  4979   1  1993  23.0    无记录   98.0    6.660     0.00       0.0        0\n",
       "4992  4993   1  1998  20.3    无记录    NaN    7.891     0.00      41.4        1\n",
       "5003  5004   0  1985  20.9    无记录   98.0   -1.000     7.92       0.0        0\n",
       "5064  5065   1  1998  20.6    无记录  106.0    3.588     0.00       0.0        0\n",
       "\n",
       "[287 rows x 10 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[lambda df :(df[\"体重指数\"]<=23.9) & (df[\"体重指数\"]>=18.5) & (df[\"糖尿病家族史\"]==\"无记录\"), :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>1992</td>\n",
       "      <td>20.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7.053</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1999</td>\n",
       "      <td>20.2</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.953</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>22.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.121</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>88</td>\n",
       "      <td>1</td>\n",
       "      <td>1987</td>\n",
       "      <td>23.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>4.429</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1976</td>\n",
       "      <td>22.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>7.024</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4974</th>\n",
       "      <td>4975</td>\n",
       "      <td>1</td>\n",
       "      <td>1995</td>\n",
       "      <td>21.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>5.691</td>\n",
       "      <td>0.00</td>\n",
       "      <td>19.8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4978</th>\n",
       "      <td>4979</td>\n",
       "      <td>1</td>\n",
       "      <td>1993</td>\n",
       "      <td>23.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>6.660</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4992</th>\n",
       "      <td>4993</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.891</td>\n",
       "      <td>0.00</td>\n",
       "      <td>41.4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5003</th>\n",
       "      <td>5004</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>20.9</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>7.92</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5064</th>\n",
       "      <td>5065</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.6</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.588</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>287 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        编号  性别  出生年份  体重指数 糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识\n",
       "49      50   0  1992  20.7    无记录   96.0    7.053     0.00       0.0        0\n",
       "60      61   1  1999  20.2    无记录   87.0    6.953     0.00       0.0        0\n",
       "83      84   0  1985  22.4    无记录   87.0    6.121     0.00       0.0        0\n",
       "87      88   1  1987  23.7    无记录   85.0    4.429     0.00       0.0        0\n",
       "93      94   1  1976  22.0    无记录   84.0    7.024     0.00      40.3        1\n",
       "...    ...  ..   ...   ...    ...    ...      ...      ...       ...      ...\n",
       "4974  4975   1  1995  21.3    无记录   96.0    5.691     0.00      19.8        0\n",
       "4978  4979   1  1993  23.0    无记录   98.0    6.660     0.00       0.0        0\n",
       "4992  4993   1  1998  20.3    无记录    NaN    7.891     0.00      41.4        1\n",
       "5003  5004   0  1985  20.9    无记录   98.0   -1.000     7.92       0.0        0\n",
       "5064  5065   1  1998  20.6    无记录  106.0    3.588     0.00       0.0        0\n",
       "\n",
       "[287 rows x 10 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def query_my_data(df):\n",
    "    return (df[\"体重指数\"]<=23.9) & (df[\"体重指数\"]>=18.5) & (df[\"糖尿病家族史\"]==\"无记录\")\n",
    "df.loc[query_my_data, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>1992</td>\n",
       "      <td>20.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7.053</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1999</td>\n",
       "      <td>20.2</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.953</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>22.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>87.0</td>\n",
       "      <td>6.121</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>88</td>\n",
       "      <td>1</td>\n",
       "      <td>1987</td>\n",
       "      <td>23.7</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>4.429</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1976</td>\n",
       "      <td>22.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>7.024</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4974</th>\n",
       "      <td>4975</td>\n",
       "      <td>1</td>\n",
       "      <td>1995</td>\n",
       "      <td>21.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>96.0</td>\n",
       "      <td>5.691</td>\n",
       "      <td>0.00</td>\n",
       "      <td>19.8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4978</th>\n",
       "      <td>4979</td>\n",
       "      <td>1</td>\n",
       "      <td>1993</td>\n",
       "      <td>23.0</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>6.660</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4992</th>\n",
       "      <td>4993</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.3</td>\n",
       "      <td>无记录</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.891</td>\n",
       "      <td>0.00</td>\n",
       "      <td>41.4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5003</th>\n",
       "      <td>5004</td>\n",
       "      <td>0</td>\n",
       "      <td>1985</td>\n",
       "      <td>20.9</td>\n",
       "      <td>无记录</td>\n",
       "      <td>98.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>7.92</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5064</th>\n",
       "      <td>5065</td>\n",
       "      <td>1</td>\n",
       "      <td>1998</td>\n",
       "      <td>20.6</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.588</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>287 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        编号  性别  出生年份  体重指数 糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识\n",
       "49      50   0  1992  20.7    无记录   96.0    7.053     0.00       0.0        0\n",
       "60      61   1  1999  20.2    无记录   87.0    6.953     0.00       0.0        0\n",
       "83      84   0  1985  22.4    无记录   87.0    6.121     0.00       0.0        0\n",
       "87      88   1  1987  23.7    无记录   85.0    4.429     0.00       0.0        0\n",
       "93      94   1  1976  22.0    无记录   84.0    7.024     0.00      40.3        1\n",
       "...    ...  ..   ...   ...    ...    ...      ...      ...       ...      ...\n",
       "4974  4975   1  1995  21.3    无记录   96.0    5.691     0.00      19.8        0\n",
       "4978  4979   1  1993  23.0    无记录   98.0    6.660     0.00       0.0        0\n",
       "4992  4993   1  1998  20.3    无记录    NaN    7.891     0.00      41.4        1\n",
       "5003  5004   0  1985  20.9    无记录   98.0   -1.000     7.92       0.0        0\n",
       "5064  5065   1  1998  20.6    无记录  106.0    3.588     0.00       0.0        0\n",
       "\n",
       "[287 rows x 10 columns]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "high, low = 23.9, 18.5\n",
    "df.query(\"@low<=体重指数<=@high & 糖尿病家族史=='无记录'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "0   1   0  1996  30.1             无记录  106.0    3.818     7.89       0.0   \n",
       "1   2   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7   \n",
       "2   3   1  1988  36.5             无记录   85.0    7.131     0.00      40.1   \n",
       "3   4   1  1992  29.5             无记录   91.0    7.041     0.00       0.0   \n",
       "4   5   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0   \n",
       "\n",
       "   患有糖尿病标识  年龄  \n",
       "0        0  26  \n",
       "1        0  34  \n",
       "2        1  34  \n",
       "3        0  30  \n",
       "4        1  24  "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取当前年份\n",
    "import datetime\n",
    "this_year = datetime.datetime.now().year\n",
    "df['年龄'] = this_year - df['出生年份']\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "0   1   0  1996  30.1             无记录  106.0    3.818     7.89       0.0   \n",
       "1   2   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7   \n",
       "2   3   1  1988  36.5             无记录   85.0    7.131     0.00      40.1   \n",
       "3   4   1  1992  29.5             无记录   91.0    7.041     0.00       0.0   \n",
       "4   5   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0   \n",
       "\n",
       "   患有糖尿病标识  年龄  体质指数-BMI  \n",
       "0        0  26         4  \n",
       "1        0  34         2  \n",
       "2        1  34         4  \n",
       "3        0  30         3  \n",
       "4        1  24         4  "
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 定义BMI指数\n",
    "def BMI(x):\n",
    "    if x < 18.5:\n",
    "        return 0\n",
    "    elif 18.5 <= x <=23.9:\n",
    "        return 1\n",
    "    elif 24 <= x <= 27.9:\n",
    "        return 2\n",
    "    elif 28 <= x <= 29.9:\n",
    "        return 3\n",
    "    elif x >= 30:\n",
    "        return 4\n",
    "    \n",
    "df['体质指数-BMI'] = df['体重指数'].apply(BMI)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试_check</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>4.818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>8.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>8.041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>8.134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5065</th>\n",
       "      <td>5066</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>36.4</td>\n",
       "      <td>父母有一方患有糖尿病</td>\n",
       "      <td>95.0</td>\n",
       "      <td>3.102</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>4</td>\n",
       "      <td>4.102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5066</th>\n",
       "      <td>5067</td>\n",
       "      <td>1</td>\n",
       "      <td>1991</td>\n",
       "      <td>37.1</td>\n",
       "      <td>叔叔或姑姑有一方患有糖尿病</td>\n",
       "      <td>94.0</td>\n",
       "      <td>6.207</td>\n",
       "      <td>6.77</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>31</td>\n",
       "      <td>4</td>\n",
       "      <td>7.207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5067</th>\n",
       "      <td>5068</td>\n",
       "      <td>0</td>\n",
       "      <td>1975</td>\n",
       "      <td>25.4</td>\n",
       "      <td>无记录</td>\n",
       "      <td>90.0</td>\n",
       "      <td>7.343</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>47</td>\n",
       "      <td>2</td>\n",
       "      <td>8.343</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5068</th>\n",
       "      <td>5069</td>\n",
       "      <td>0</td>\n",
       "      <td>1972</td>\n",
       "      <td>28.5</td>\n",
       "      <td>父母有一方患有糖尿病</td>\n",
       "      <td>101.0</td>\n",
       "      <td>6.268</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "      <td>3</td>\n",
       "      <td>7.268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5069</th>\n",
       "      <td>5070</td>\n",
       "      <td>0</td>\n",
       "      <td>1976</td>\n",
       "      <td>49.9</td>\n",
       "      <td>无记录</td>\n",
       "      <td>88.0</td>\n",
       "      <td>3.732</td>\n",
       "      <td>29.71</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>46</td>\n",
       "      <td>4</td>\n",
       "      <td>4.732</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5070 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "0        1   0  1996  30.1             无记录  106.0    3.818     7.89       0.0   \n",
       "1        2   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7   \n",
       "2        3   1  1988  36.5             无记录   85.0    7.131     0.00      40.1   \n",
       "3        4   1  1992  29.5             无记录   91.0    7.041     0.00       0.0   \n",
       "4        5   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0   \n",
       "...    ...  ..   ...   ...             ...    ...      ...      ...       ...   \n",
       "5065  5066   1  1992  36.4      父母有一方患有糖尿病   95.0    3.102     0.00       0.0   \n",
       "5066  5067   1  1991  37.1   叔叔或姑姑有一方患有糖尿病   94.0    6.207     6.77       0.0   \n",
       "5067  5068   0  1975  25.4             无记录   90.0    7.343     0.00       0.0   \n",
       "5068  5069   0  1972  28.5      父母有一方患有糖尿病  101.0    6.268     8.99       0.0   \n",
       "5069  5070   0  1976  49.9             无记录   88.0    3.732    29.71       0.0   \n",
       "\n",
       "      患有糖尿病标识  年龄  体质指数-BMI  口服耐糖量测试_check  \n",
       "0           0  26         4          4.818  \n",
       "1           0  34         2          0.000  \n",
       "2           1  34         4          8.131  \n",
       "3           0  30         3          8.041  \n",
       "4           1  24         4          8.134  \n",
       "...       ...  ..       ...            ...  \n",
       "5065        0  30         4          4.102  \n",
       "5066        0  31         4          7.207  \n",
       "5067        0  47         2          8.343  \n",
       "5068        0  50         3          7.268  \n",
       "5069        1  46         4          4.732  \n",
       "\n",
       "[5070 rows x 13 columns]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.assign(\n",
    "   口服耐糖量测试_check = lambda x:x['口服耐糖量测试'] +1 \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   编号  性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  \\\n",
       "0   1   0  1996  30.1             无记录  106.0    3.818     7.89       0.0   \n",
       "1   2   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7   \n",
       "2   3   1  1988  36.5             无记录   85.0    7.131     0.00      40.1   \n",
       "3   4   1  1992  29.5             无记录   91.0    7.041     0.00       0.0   \n",
       "4   5   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0   \n",
       "\n",
       "   患有糖尿病标识  年龄  体质指数-BMI 口服耐糖量测试-OGTT  \n",
       "0        0  26         4            0  \n",
       "1        0  34         2            0  \n",
       "2        1  34         4            0  \n",
       "3        0  30         3            0  \n",
       "4        1  24         4            0  "
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['口服耐糖量测试-OGTT'] = ''\n",
    "df.loc[df['口服耐糖量测试']<= 7.8, '口服耐糖量测试-OGTT'] = 0\n",
    "df.loc[df['口服耐糖量测试']> 7.8, '口服耐糖量测试-OGTT'] = 1\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop(['编号'], axis=1, inplace=True)   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1             无记录  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5             无记录   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5             无记录   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI 口服耐糖量测试-OGTT  \n",
       "0  26         4            0  \n",
       "1  34         2            0  \n",
       "2  34         4            0  \n",
       "3  30         3            0  \n",
       "4  24         4            0  "
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "df[\"姓名\"] = \"yifan\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1             无记录  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5             无记录   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5             无记录   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI 口服耐糖量测试-OGTT     姓名  \n",
       "0  26         4            0  yifan  \n",
       "1  34         2            0  yifan  \n",
       "2  34         4            0  yifan  \n",
       "3  30         3            0  yifan  \n",
       "4  24         4            0  yifan  "
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1             无记录  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5             无记录   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5             无记录   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI 口服耐糖量测试-OGTT        姓名  \n",
       "0  26         4            0     yifan  \n",
       "1  34         2            0  hanguang  \n",
       "2  34         4            0  hanguang  \n",
       "3  30         3            0     yifan  \n",
       "4  24         4            0     yifan  "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1:2, \"姓名\"] = \"hanguang\"\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[1:2, \"姓名\"] = \"hanguang\"\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>孙悟空</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>八戒</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>八戒</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>孙悟空</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>孙悟空</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1             无记录  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5             无记录   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5             无记录   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI  口服耐糖量测试-OGTT   姓名  \n",
       "0  26         4             0  孙悟空  \n",
       "1  34         2             0   八戒  \n",
       "2  34         4             0   八戒  \n",
       "3  30         3             0  孙悟空  \n",
       "4  24         4             0  孙悟空  "
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.replace(['yifan','hanguang'],[\"孙悟空\",\"八戒\"],inplace=True)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>无记录</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>无记录</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1             无记录  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5             无记录   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5             无记录   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5             无记录   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI  口服耐糖量测试-OGTT        姓名  \n",
       "0  26         4             0     yifan  \n",
       "1  34         2             0  hanguang  \n",
       "2  34         4             0  hanguang  \n",
       "3  30         3             0     yifan  \n",
       "4  24         4             0     yifan  "
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict_ = {\"孙悟空\":'yifan', \"八戒\":'hanguang',}\n",
    "df.replace(dict_, inplace=True)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# feature_dict = {'无记录':0,'叔叔或者姑姑有一方患有糖尿病':1,'叔叔或姑姑有一方患有糖尿病':1,'父母有一方患有糖尿病':2}\n",
    "# df['糖尿病家族史'] = df['糖尿病家族史'].map(feature_dict)\n",
    "# df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>叔叔或者姑姑有一方患有糖尿病</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数          糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  \\\n",
       "0   0  1996  30.1               0  106.0    3.818     7.89       0.0        0   \n",
       "1   0  1988  27.5               0   84.0   -1.000     0.00      14.7        0   \n",
       "2   1  1988  36.5               0   85.0    7.131     0.00      40.1        1   \n",
       "3   1  1992  29.5               0   91.0    7.041     0.00       0.0        0   \n",
       "4   0  1998  42.0  叔叔或者姑姑有一方患有糖尿病    NaN    7.134     0.00       0.0        1   \n",
       "\n",
       "   年龄  体质指数-BMI  口服耐糖量测试-OGTT        姓名  \n",
       "0  26         4             0     yifan  \n",
       "1  34         2             0  hanguang  \n",
       "2  34         4             0  hanguang  \n",
       "3  30         3             0     yifan  \n",
       "4  24         4             0     yifan  "
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['糖尿病家族史'] = df['糖尿病家族史'].replace('无记录', 0)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>出生年份</th>\n",
       "      <th>体重指数</th>\n",
       "      <th>糖尿病家族史</th>\n",
       "      <th>舒张压</th>\n",
       "      <th>口服耐糖量测试</th>\n",
       "      <th>胰岛素释放实验</th>\n",
       "      <th>肱三头肌皮褶厚度</th>\n",
       "      <th>患有糖尿病标识</th>\n",
       "      <th>年龄</th>\n",
       "      <th>体质指数-BMI</th>\n",
       "      <th>口服耐糖量测试-OGTT</th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1996</td>\n",
       "      <td>30.1</td>\n",
       "      <td>0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>3.818</td>\n",
       "      <td>7.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1988</td>\n",
       "      <td>27.5</td>\n",
       "      <td>0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>-1.000</td>\n",
       "      <td>0.00</td>\n",
       "      <td>14.7</td>\n",
       "      <td>0</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1988</td>\n",
       "      <td>36.5</td>\n",
       "      <td>0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>7.131</td>\n",
       "      <td>0.00</td>\n",
       "      <td>40.1</td>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>hanguang</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1992</td>\n",
       "      <td>29.5</td>\n",
       "      <td>0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>7.041</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1998</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.134</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>yifan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   性别  出生年份  体重指数 糖尿病家族史    舒张压  口服耐糖量测试  胰岛素释放实验  肱三头肌皮褶厚度  患有糖尿病标识  年龄  \\\n",
       "0   0  1996  30.1      0  106.0    3.818     7.89       0.0        0  26   \n",
       "1   0  1988  27.5      0   84.0   -1.000     0.00      14.7        0  34   \n",
       "2   1  1988  36.5      0   85.0    7.131     0.00      40.1        1  34   \n",
       "3   1  1992  29.5      0   91.0    7.041     0.00       0.0        0  30   \n",
       "4   0  1998  42.0      1    NaN    7.134     0.00       0.0        1  24   \n",
       "\n",
       "   体质指数-BMI  口服耐糖量测试-OGTT        姓名  \n",
       "0         4             0     yifan  \n",
       "1         2             0  hanguang  \n",
       "2         4             0  hanguang  \n",
       "3         3             0     yifan  \n",
       "4         4             0     yifan  "
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.replace('叔叔*',1,regex=True,inplace=True)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
